package routes

import (
	"github.com/gin-gonic/gin"
	"html/template"
	controllers "supervideo/app/http/controllers/front"
)

func RegisterFrontRoutes(r *gin.Engine) {

	r.SetFuncMap(template.FuncMap{
		"seq": func(start, end int) []int {
			a := make([]int, end-start+1)
			for i := range a {
				a[i] = start + i
			}
			return a
		},
		"sub": func(nums ...int) int {
			result := 0
			for _, num := range nums {
				result -= num
			}
			return result
		},
		"add": func(a, b int) int {
			return a + b
		},
		"max": func(a, b int) int {
			if a > b {
				return a
			}
			return b
		},
		"min": func(a, b int) int {
			if a < b {
				return a
			}
			return b
		},
	})
	r.LoadHTMLGlob("views/*.html")
	r.Static("/static", "./static")

	// 测试一个 v1 的路由组，我们所有的 v1 版本的路由都将存放到这里
	v1 := r.Group("/")
	{
		ic := new(controllers.IndexController)
		// 首页
		v1.GET("/", ic.Index)

		lc := new(controllers.ListController)
		// 列表页
		v1.GET("/list/:zone_id", lc.Index)

		dc := new(controllers.DetailController)
		// 详情页
		v1.GET("/detail/:video_id", dc.Detail)

	}
}
